﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace MediSIIM.BizComponent.GuiZhouSASSYB
{
    [Serializable]
    public class GuiZhouSASSYBTradeParms
    {
        public const string XmlHead = "<?xml version=\"1.0\" encoding=\"GBK\" standalone=\"yes\" ?>";
        public string TradeId;
        /// <summary>
        /// 医保交易号
        /// </summary>
        public string ybjyhm;
        /// <summary>
        /// 交易流水号
        /// </summary>
        public double TradeNo;

        public string this[string name]
        {
            set
            {
                name = name.ToLower();
                Items.Add(name, value);
                Keys.Add(name);
            }
            get
            {
                name = name.ToLower();
                return OutItems.ContainsKey(name) ? OutItems[name] : "";
            }
        }
        public string XmlIn
        {
            get
            {
                if (Items.Count==0)
                {
                    return InData;
                }
                var xmlin = XmlHead + "<data>";
                foreach (var item in Keys)
                {
                    xmlin += string.Format("<{0}>{1}</{0}>", item, Items[item]);
                }
                xmlin = xmlin + "</data>";
                return xmlin;
            }
        }
        /// <summary>
        /// 输入参数集合
        /// </summary>
        public Dictionary<string, string> Items { get; set; }
        /// <summary>
        /// 输出参数集合
        /// </summary>
        public Dictionary<string, string> OutItems { get; set; }
        /// <summary>
        /// 输入参数名称集合，按顺序
        /// </summary>
        public List<string> Keys { get; set; }
        /// <summary>
        /// 输出参数名称集合，按顺序
        /// </summary>
        public List<string> OutKeys { get; set; }

        public GuiZhouSASSYBTradeParms()
        {

        }

        public GuiZhouSASSYBTradeParms(string tradeId)
        {
            Items = new Dictionary<string, string>();
            OutItems = new Dictionary<string, string>();
            Keys = new List<string>();
            OutKeys = new List<string>();
            this.TradeId = tradeId;
            this.ybjyhm = string.Empty.PadRight(20);
            this.jyyzm = string.Empty.PadRight(15);
            this.OutData = string.Empty.PadRight(3000);
        }

        public string jyyzm;
        public string OutData;
        private string InData;

        public void parseout()
        {
            try
            {
                var xmldom = new XmlDocument();
                xmldom.LoadXml(OutData);
            foreach (XmlNode item in xmldom.SelectSingleNode("/output").ChildNodes)
            {
                OutItems.Add(item.Name.ToLower(), item.InnerText);
                OutKeys.Add(item.Name.ToLower());
            }
            }
            catch (Exception)
            {
            }
        }

        internal string GetInput(string p)
        {
            throw new NotImplementedException();
        }
    }
}
